package com.cun.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

/**
 * Created by zhen on 2016/10/14.
 */
@Controller
public class RedisController {

    protected static Logger logger= LoggerFactory.getLogger(RedisController.class);

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @Resource(name="stringRedisTemplate")
    ValueOperations<String,String> valOpsStr;

    @RequestMapping("set")
    public String setKeyAndValue(String key,String value){
        logger.debug("op set:key={},value={}",key,value);
        valOpsStr.set(key, value);
        return "Set Ok";
    }
    @RequestMapping("get")
    public String getKey(String key){

        String rs = valOpsStr.get(key);
        logger.debug("op get:key={}  ret={}",key,rs);

        return rs;
    }
}
